package com.edais.service.imp;

import java.util.*;

import com.edais.dao.TurnOutDao;
import com.edais.persistence.SystemSettingMapper;
import com.edais.service.SpringFestivalService;
import com.edais.service.ldap.LdapService;
import com.yunzhi.domain.ResultCode;
import com.yunzhi.domain.ResultConstant;
import com.yunzhi.domain.ResultDTO;
import com.yunzhi.util.ResponseUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SpringFestivalServiceImpl implements SpringFestivalService {
	
	private static final Log logger = LogFactory.getLog(SpringFestivalServiceImpl.class);
	
	@Autowired
    private SystemSettingMapper systemSettingMapper;
	@Autowired
	private LdapService ldapService;
	@Autowired
	private TurnOutDao turnOutdao;
	
	/**
	 * 获取过年气氛图标(app)
	 */
	@Override
	public ResultDTO getSpringFestivalIcon(Map<String, Object> map) throws Exception{
		ResultDTO<Map> resultDTO;
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String cjtbkg= systemSettingMapper.getSystemSettingValueByName("cjtbkg").toString();// 图标开关：(1-开启，0-关闭)
		String iconPath= systemSettingMapper.getSystemSettingValueByName("spring_festival_icon_path").toString();

		/*String cjtbkg= ldapService.getSystemSetting("cjtbkg").getValue();// 图标开关：(1-开启，0-关闭)
		String iconPath=ldapService.getSystemSetting("spring_festival_icon_path").getValue();*/
		//获取气氛图标图片
		try{
			//图标开关状态判断，为1显示气氛图标，否则为平常的
			String[] arrays1;
			String[] arrays2;
			if("1".equals(cjtbkg)){
				/*String springList1 = ldapService.getSystemSetting("spring_festival_select_icon").getValue();
				String springList2 = ldapService.getSystemSetting("spring_festival_default_icon").getValue();*/
				String springList1 = systemSettingMapper.getSystemSettingValueByName("spring_festival_select_icon").toString();
				String springList2 = systemSettingMapper.getSystemSettingValueByName("spring_festival_default_icon").toString();
				arrays1=springList1.split("\\|");
				arrays2=springList2.split("\\|");				
			}else{
				/*String usualList1 = ldapService.getSystemSetting("usual_select_icon").getValue();
				String usualList2 = ldapService.getSystemSetting("usual_default_icon").getValue();*/
				String usualList1 = systemSettingMapper.getSystemSettingValueByName("usual_select_icon").toString();
				String usualList2 = systemSettingMapper.getSystemSettingValueByName("usual_default_icon").toString();
				arrays1=usualList1.split("\\|");
				arrays2=usualList2.split("\\|");
			}
			if(arrays1==null){
				arrays1=new String[]{};
			}
			if(arrays2==null){
				arrays2=new String[]{};
			}
			Map<String,String> parmMap=new TreeMap<String,String>();
			parmMap.put("cjtbkg", cjtbkg);
			for (int i = 0; i < arrays1.length; i++) {
				parmMap.put("ficonSelect_"+"icon"+(i+1), iconPath+arrays1[i]);
				parmMap.put("ficonDefault_"+"icon"+(i+1), iconPath+arrays2[i]);
			}

			resultDTO = new ResultDTO<>(ResultCode.SUCCESS);
			resultDTO.setResMsg("获取初始化图标成功");
			resultDTO.setRecord(parmMap);
		}catch(Exception e){
			logger.error("==================获取初始化图标失败:",e);
			resultMap.put("cjtbkg", "0");
			resultDTO = new ResultDTO<>(ResultCode.FAILED);
			resultDTO.setResMsg("获取初始化图标失败");
			resultDTO.setRecord(resultMap);
		}
		return resultDTO;
	}
	
//	/**
//	 * 获取过年气氛图标(weixin)
//	 */
//	@Override
//	public Map<String, Object> getWxSpringFestivalIcon(Map<String, Object> map) throws Exception {
//		Map<String, Object> resultMap = new HashMap<String, Object>();
//		String cjtbkg= systemSettingMapper.getSystemSettingValue("cjtbkg");// 图标开关：(1-开启，0-关闭)
//		String iconPath=systemSettingMapper.getSystemSettingValue("spring_festival_icon_path");
//		//获取气氛图标图片
//		try{
//			//图标开关状态判断，为1显示气氛图标，否则为平常的
//			String[] arrays1;
//			String[] arrays2;
//			if("1".equals(cjtbkg)){
//				String springList1 = systemSettingMapper.getSystemSettingValue("wx_spring_festival_select_icon");
//				String springList2 = systemSettingMapper.getSystemSettingValue("wx_spring_festival_default_icon");
//				arrays1=springList1.split("\\|");
//				arrays2=springList2.split("\\|");
//			}else{
//				String usualList1 = systemSettingMapper.getSystemSettingValue("usual_select_icon");
//				String usualList2 = systemSettingMapper.getSystemSettingValue("usual_default_icon");
//				arrays1=usualList1.split("\\|");
//				arrays2=usualList2.split("\\|");
//			}
//			if(arrays1==null){
//				arrays1=new String[]{};
//			}
//			if(arrays2==null){
//				arrays2=new String[]{};
//			}
//			for (int i = 0; i < arrays1.length; i++) {
//				Map<String,String> parmMap=new HashMap<String,String>();
//				parmMap.put("ficonSelect", iconPath+arrays1[i]);
//				parmMap.put("ficonDefault", iconPath+arrays2[i]);
//				resultMap.put("icon"+(i+1), parmMap);
//			}
//			resultMap.put("cjtbkg", cjtbkg);
//			resultMap.put("rescode",  Consts.SUCCESS_CODE);
//			resultMap.put("resmsg", "");
//			resultMap.put("resmsg_cn", "获取过年气氛图标成功");
//		}catch(Exception e){
//			logger.error("==================获取过年气氛图标失败:",e);
//			resultMap.put("cjtbkg", "0");
//			resultMap.put("rescode",  Consts.ERROR_CODE);
//			resultMap.put("resmsg", "");
//			resultMap.put("resmsg_cn", "获取过年气氛图标失败");
//		}
//		return resultMap;
//	}

}
